from abc import ABC, abstractmethod


# 基类：咖啡
class Coffee(ABC):
    @abstractmethod
    def get_name(self):
        pass

    # 加糖
    def add_sugar(self):
        print("加糖")

    # 加奶
    def add_milk(self):
        print("加奶")


# 美式咖啡
class AmericanCoffee(Coffee):
    def get_name(self):
        return "美式咖啡"


# 拿铁咖啡
class LattaCoffee(Coffee):
    def get_name(self):
        return "拿铁咖啡"


# 咖啡工厂接口
class CoffeeFactory(ABC):
    @abstractmethod
    def create_coffee(self):
        pass


# 美式咖啡工厂
class AmericanCoffeeFactory(CoffeeFactory):
    def create_coffee(self):
        return AmericanCoffee()


# 拿铁咖啡工厂
class LattaCoffeeFactory(CoffeeFactory):
    def create_coffee(self):
        return LattaCoffee()


# 咖啡店类
class CoffeeStore:
    def __init__(self):
        self.factory = None

    def set_factory(self, factory: CoffeeFactory):
        self.factory = factory

    def order_coffee(self):
        # 调用生产咖啡的方法
        coffee = self.factory.create_coffee()
        # 添加配料
        coffee.add_milk()
        coffee.add_sugar()
        return coffee


# 客户端代码
if __name__ == "__main__":
    # 创建咖啡店对象
    store = CoffeeStore()

    # 创建工厂对象
    factory = AmericanCoffeeFactory()

    # 设置咖啡工厂
    store.set_factory(factory)

    # 点咖啡
    coffee = store.order_coffee()

    # 打印咖啡名称
    print(coffee.get_name())
